<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="成本域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costDomain">
              <a-input v-model="model.costDomain" placeholder="请输入成本域"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description1">
              <a-input v-model="model.description1" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本中心" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costCenter">
              <a-input v-model="model.costCenter" placeholder="请输入成本中心"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明(简称)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="descriptionAbbr">
              <a-input v-model="model.descriptionAbbr" placeholder="请输入说明(简称)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入库单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inboundOrderNo">
              <a-input v-model="model.inboundOrderNo" placeholder="请输入入库单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemSequence">
              <a-input v-model="model.itemSequence" placeholder="请输入项次"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemOrder">
              <a-input v-model="model.itemOrder" placeholder="请输入项序"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出入库码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inOutCode">
              <a-input v-model="model.inOutCode" placeholder="请输入出入库码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="documentDate">
              <a-input v-model="model.documentDate" placeholder="请输入单据日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="料号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialCode">
              <a-input v-model="model.materialCode" placeholder="请输入料号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入品名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specification">
              <a-input v-model="model.specification" placeholder="请输入规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本分群" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costGroup">
              <a-input v-model="model.costGroup" placeholder="请输入成本分群"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description2">
              <a-input v-model="model.description2" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品特征" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productFeature">
              <a-input v-model="model.productFeature" placeholder="请输入产品特征"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工单号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workOrderNo">
              <a-input v-model="model.workOrderNo" placeholder="请输入工单号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仓库编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warehouseCode">
              <a-input v-model="model.warehouseCode" placeholder="请输入仓库编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description3">
              <a-input v-model="model.description3" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchNo">
              <a-input v-model="model.batchNo" placeholder="请输入批号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costUnit">
              <a-input v-model="model.costUnit" placeholder="请输入成本单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description4">
              <a-input v-model="model.description4" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentQty">
              <a-input v-model="model.currentQty" placeholder="请输入本期异动数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-材料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceMaterial">
              <a-input v-model="model.currentUnitPriceMaterial" placeholder="请输入本期异动单价-材料"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-人工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceLabor">
              <a-input v-model="model.currentUnitPriceLabor" placeholder="请输入本期异动单价-人工"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-加工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceProcessing">
              <a-input v-model="model.currentUnitPriceProcessing" placeholder="请输入本期异动单价-加工"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-制费一" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceOverhead1">
              <a-input v-model="model.currentUnitPriceOverhead1" placeholder="请输入本期异动单价-制费一"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-制费二" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceOverhead2">
              <a-input v-model="model.currentUnitPriceOverhead2" placeholder="请输入本期异动单价-制费二"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-制费三" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceOverhead3">
              <a-input v-model="model.currentUnitPriceOverhead3" placeholder="请输入本期异动单价-制费三"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-制费四" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceOverhead4">
              <a-input v-model="model.currentUnitPriceOverhead4" placeholder="请输入本期异动单价-制费四"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价-制费五" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceOverhead5">
              <a-input v-model="model.currentUnitPriceOverhead5" placeholder="请输入本期异动单价-制费五"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentUnitPriceTotal">
              <a-input v-model="model.currentUnitPriceTotal" placeholder="请输入本期异动单价"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-材料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountMaterial">
              <a-input v-model="model.currentAmountMaterial" placeholder="请输入本期异动金额-材料"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-人工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountLabor">
              <a-input v-model="model.currentAmountLabor" placeholder="请输入本期异动金额-人工"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-加工费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountProcessing">
              <a-input v-model="model.currentAmountProcessing" placeholder="请输入本期异动金额-加工费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-制费一" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountOverhead1">
              <a-input v-model="model.currentAmountOverhead1" placeholder="请输入本期异动金额-制费一"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-制费二" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountOverhead2">
              <a-input v-model="model.currentAmountOverhead2" placeholder="请输入本期异动金额-制费二"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-制费三" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountOverhead3">
              <a-input v-model="model.currentAmountOverhead3" placeholder="请输入本期异动金额-制费三"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-制费四" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountOverhead4">
              <a-input v-model="model.currentAmountOverhead4" placeholder="请输入本期异动金额-制费四"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额-制费五" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountOverhead5">
              <a-input v-model="model.currentAmountOverhead5" placeholder="请输入本期异动金额-制费五"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期异动金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAmountTotal">
              <a-input v-model="model.currentAmountTotal" placeholder="请输入本期异动金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <a-input v-model="model.year" placeholder="请输入年份"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="月份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="month">
              <a-input v-model="model.month" placeholder="请输入月份"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="据点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="site">
              <a-input v-model="model.site" placeholder="请输入据点"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'Axcq509ChDetailForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/axcq509ChDetail/add",
          edit: "/ch/axcq509ChDetail/edit",
          queryById: "/ch/axcq509ChDetail/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>